package day09.edu;

// Created: 09/09/2025, ChangJiang Ru
public class ThrowTest {
    public static void main(String[] args) {
        Student s1 = new Student();
//        s1.registerId(10);
        try {
            s1.registerId(-10);
        } catch (Exception e) {
            e.printStackTrace();
            System.out.println(e.getMessage());
        }
        System.out.println(s1);

        try {
            s1.registerName("Tom");

        } catch (Exception e) {
            e.printStackTrace();
            System.out.println(e.getMessage());
        }
    }

}

class Student {
    int id;
    String name;

    public void registerId(int id) throws Exception {
        if (id > 0) this.id = id;
//        else throw new RuntimeException("Input error");
        else
            throw new BelowZeroException("Input error");
    }


    public void registerName(String name) throws Exception {
        if (name == "abc")
            this.name = name;
        else
            throw new Exception("Exception error");
    }

    @Override
    public String toString() {
        return "Student{" + "id = '" + this.id + '\'' + '}';
    }
}